/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.shop;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.shop.entity.shop.HkShopTrademark;
import com.thinkgem.jeesite.modules.hk.shop.service.shop.HkShopTrademarkService;

/**
 * 店铺商标信息Controller
 * @author 李欣荣
 * @version 2018-10-09
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/shop/hkShopTrademark")
public class HkShopTrademarkController extends BaseController {

	@Autowired
	private HkShopTrademarkService hkShopTrademarkService;
	
	@ModelAttribute
	public HkShopTrademark get(@RequestParam(required=false) String id) {
		HkShopTrademark entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkShopTrademarkService.get(id);
		}
		if (entity == null){
			entity = new HkShopTrademark();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:shop:hkShopTrademark:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkShopTrademark hkShopTrademark, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkShopTrademark> page = hkShopTrademarkService.findPage(new Page<HkShopTrademark>(request, response), hkShopTrademark); 
		model.addAttribute("page", page);
		return "hk/shop/shop/hkShopTrademarkList";
	}

	@RequiresPermissions("shop:shop:hkShopTrademark:view")
	@RequestMapping(value = "form")
	public String form(HkShopTrademark hkShopTrademark, Model model) {
		model.addAttribute("hkShopTrademark", hkShopTrademark);
		return "hk/shop/shop/hkShopTrademarkForm";
	}

	@RequiresPermissions("shop:shop:hkShopTrademark:edit")
	@RequestMapping(value = "save")
	public String save(HkShopTrademark hkShopTrademark, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkShopTrademark)){
			return form(hkShopTrademark, model);
		}
		hkShopTrademarkService.save(hkShopTrademark);
		addMessage(redirectAttributes, "保存店铺商标信息成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkShopTrademark/?repage";
	}
	
	@RequiresPermissions("shop:shop:hkShopTrademark:edit")
	@RequestMapping(value = "delete")
	public String delete(HkShopTrademark hkShopTrademark, RedirectAttributes redirectAttributes) {
		hkShopTrademarkService.delete(hkShopTrademark);
		addMessage(redirectAttributes, "删除店铺商标信息成功");
		return "redirect:"+Global.getAdminPath()+"/shop/shop/hkShopTrademark/?repage";
	}

}